package com.zmht.beike.biz.impl;

import java.io.Serializable;
import java.util.List;

import com.zmht.beike.biz.ImonthcontentBiz;
import com.zmht.beike.core.BaseBizImpl;
import com.zmht.beike.po.TImonthcontent;

public class ImonthcontentBizImpl extends BaseBizImpl implements
		ImonthcontentBiz {

	public TImonthcontent findById(Serializable id) {
		
		return (TImonthcontent)this.getImonthcontentDAO().findById(TImonthcontent.class, id);
	}

	public List<TImonthcontent> getTImonthcontent(Integer teacherId,String month,
			int startIndex, int pageSize) {
		String hql = "from TImonthcontent t where t.month="+month+" and t.monthID=null and t.teacherId="+teacherId;
		return this.getImonthcontentDAO().findByPage(hql, startIndex, pageSize);
	}

	public int getTImonthcontentTotal(Integer teacherId,String month) {
		String hql = "from TImonthcontent t where t.month="+month+" and t.monthID=null and t.teacherId="+teacherId;
		
		return this.getImonthcontentDAO().findByPageAmount(hql);
	}

	public boolean updateImonthcontent(TImonthcontent imonthcontent) {
		try{
			this.getImonthcontentDAO().updateObj(imonthcontent);
		}catch(Exception e){
			return false;
		}
		return true;
	}

	public boolean delTImonthcontent(Serializable id) {
		try{
			Object obj = this.getImonthcontentDAO().findById(TImonthcontent.class, id);
			if(obj!=null){
				this.getImonthcontentDAO().deleteObj(obj);
			}
		}catch(Exception e){
			return false;
		}
		return true;
	}

	public boolean saveTImonthcontent(TImonthcontent monthcontent) {
		try{
			this.getImonthcontentDAO().saveObj(monthcontent);
		}catch(Exception e){
			return false;
		}
		return true;
	}

	public List<TImonthcontent> getTImonthcontentEdit(Integer targetId,
			Integer teacherId, String month, int startIndex, int pageSize) {
		String hql = "from TImonthcontent t where t.iaimId = "+targetId+" and t.month="+month+" and t.teacherId="+teacherId;
		return this.getImonthcontentDAO().findByPage(hql, startIndex, pageSize);
	}

	public int getTImonthcontentEditTotal(Integer targetId, Integer teacherId,
			String month) {
		String hql = "from TImonthcontent t where t.iaimId = "+targetId+" and t.month="+month+" and t.teacherId="+teacherId;
		return this.getImonthcontentDAO().findByPageAmount(hql);
	}

}
